/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 */

'Gio.Message'.namespace();

Gio.Message = function() {};

Gio.Message.yesButton = 'Yes';
Gio.Message.noButton = 'No';

Gio.Message.confirm = function(message, callback, data) {
	message += '<p class="buttons_demo fl">' 
			+ '<a href="javascript: void(0);" id="g_a_confirm_yes_button" class="button green"><small class="icon check"></small><span>' + this.yesButton + '</span></a>'
			+ '<a href="javascript: Gio.Message.confirm.cancel();" class="button red"><small class="icon cross"></small><span>' + this.noButton + '</span></a>'
			+ '</p><div class="clear"></div>';
	$().Message({ type: 'notice', text: message, time: 100000, click: true });
	$('#g_a_confirm_yes_button').click(function() {
		Gio.Message.confirm.yes(callback, data)
	});
};

Gio.Message.confirm.yes = function(callback, data) {
	if (callback != undefined) {
		eval(callback + '(data)');
	}
	return true;
}

Gio.Message.confirm.cancel = function() {
	$('#messages').click();
}

Gio.Message.success = function(message) {
	message = Gio.Message.format(message); 
	$().Message({ type: 'success', text: message + '<div class="clear"></div>', time: 4000, click: true });
};

Gio.Message.error = function(message) {
	message = Gio.Message.format(message);
	$().Message({ type: 'error', text: message + '<div class="clear"></div>', time: 4000, click: true });
};

Gio.Message.notice = function(message) {
	$().Message({ type: 'notice', text: message + '<div class="clear"></div>' });
};

Gio.Message.format = function(message) {
	if (message.indexOf('<ul>') == -1) {
		message = '<ul><li><b>' + message + '</b></li></ul>';
	}
	return message;
};

Gio.Message.form = function(html) {
	$().Message({ type: 'notice', text: html + '<div class="clear"></div>', time: 18000000, click: false });
};